package com.halfsword.creativecraft.datagen;

import com.halfsword.creativecraft.CreativeCraft;
import com.halfsword.creativecraft.loot.AddItemModifier;
import com.halfsword.creativecraft.loot.AddSusSandItemModifier;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
import net.minecraftforge.common.data.GlobalLootModifierProvider;
import net.minecraftforge.common.loot.LootTableIdCondition;

public class GlobalLootModifiersProvider extends GlobalLootModifierProvider {

    public GlobalLootModifiersProvider(PackOutput output) {
        super(output, CreativeCraft.MOD_ID);
    }

    @Override
    protected void start() {
        // 添加从草方块掉落马铃薯的全局战利品修改器
        add("potatoes_from_grass", new AddItemModifier(
                new LootItemCondition[] {
                        // 条件1：当方块是草方块时
                        LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.GRASS).build(),
                        // 条件2：15%的触发几率
                        LootItemRandomChanceCondition.randomChance(0.15f).build()
                },
                Items.POTATO // 添加的物品
        ));

        // 添加从僵尸掉落马铃薯的全局战利品修改器
        add("potatoes_from_zombie", new AddItemModifier(
                new LootItemCondition[] {
                        // 条件1：当战利品表来自僵尸
                        new LootTableIdCondition.Builder(
                                // 使用 parse 方法替代过时的构造函数
                                ResourceLocation.parse("minecraft:entities/zombie") // 解析完整资源路径
                        ).build(),
                        // 条件2：50%的触发几率
                        LootItemRandomChanceCondition.randomChance(0.5f).build()
                },
                Items.POTATO
        ));

        // 添加从丛林神庙宝箱掉落马铃薯的全局战利品修改器
        add("potatoes_from_jungle_temples", new AddItemModifier(
                new LootItemCondition[] {
                        // 条件1：当战利品表来自丛林神庙宝箱
                        new LootTableIdCondition.Builder(

                                ResourceLocation.parse("minecraft:chests/jungle_pyramid")
                        ).build(),
                        // 条件2：50%的触发几率
                        LootItemRandomChanceCondition.randomChance(0.5f).build()
                },
                Items.POTATO
        ));
        // 添加从可疑沙子获取马铃薯的全局战利品修改器
        add("potatoes_from_sus_sand", new AddSusSandItemModifier(
                new LootItemCondition[] {
                        // 条件1：当战利品表来自可疑沙子
                        new LootTableIdCondition.Builder(

                                ResourceLocation.parse("archaeology/desert_pyramid")
                        ).build(),
                        // 条件2：40%*17%的综合触发几率
                        LootItemRandomChanceCondition.randomChance(0.4f).build()
                },
                Items.POTATO
        ));
    }
}
